function login2(){
	$(".head-r").children("li").children("a").hover(
		function(){
			$(this).addClass("active2");
		},
		function(){
			$(this).removeClass("active2");
			
		}
	)
}

function login(){
	class Login{
	        constructor(){
	            // 选择各种元素
	            this.user = document.getElementById("user");
	            this.pass = document.getElementById("pass");
	            this.submit = document.getElementById("submit");
	            this.msg = document.querySelector(".msg");
	            // 提前准备接口
	            this.url = "http://api.icodeilife.cn:81/user";
	            // 绑定事件
	            this.addEvent()
	        }
	        addEvent(){
	            var that = this;
	            this.submit.onclick = function(){
	                // 注册请求之前获取输入框内容
	                that.u = that.user.value;
	                that.p = that.pass.value;
	                // 开启请求
	                that.load();
	            }
	        }
	        load(){
	            ajax({
	                url:this.url,
	                data:{      // 根据接口文档，发送数据
	                    type: "login",
	                    user: this.u,
	                    pass: this.p
	                }
	            }).then((res)=>{
	                // 请求成功后，查看数据，处理数据
	                console.log(res);
	                this.res = JSON.parse(res);
	                // 渲染结果
	                this.display();
	            })
	        }
	        display(){
	            switch(this.res.code){
	                case 0:
	                    this.msg.innerHTML = this.res.msg + "，3秒后到注册";
	                    setTimeout(() => {
	                        location.href = "register.html";
	                    }, 3000);
	                    break;
	                case 1:
	                    this.msg.innerHTML = "登录成功，3秒后到首页";
	                    setTimeout(() => {
	                        location.href = "../index.html";
	                    }, 3000);
	
	                    sessionStorage.setItem("userMsg",JSON.stringify(this.res.msg));
	                    
	                    break;
	                case 2:
	                    this.msg.innerHTML = this.res.msg + "，请重新输入";
	                    this.user.value = this.pass.value = "";
	                    this.user.focus();
	            }
	        }
	    }
	
	    new Login;
}